/*********************  企业员工设置  **************************/

	var _common = xbdunRequire("common");
	var _targeTable = null;		//员工表
	var _roleTargeTable = null;	//设置权限,角色表
	var userInfo = null;		//员工所有信息
	var code = 0;				//选中部门code
	var userDepRole = null;		//员工在部门下已有的角色权限
	var userAllPower = null;	//员工所有权限
	var isSearch = false;
	
	$(function() {
		/*****************************   初始化员工表   ******************************/
		setTimeout(function(){_targeTable = new TableInit($('#tb_user_info'))},1000);
		
		/*****************************   添加员工--弹出查询员工层    *******************/
		$("#btn_100101103100").on("click",function(){
			_common.showUserInfo({isAdd:true,fnSubmit:function(data){
					$('#frm_addOrModify').get(0).reset();
					if(data['imgUrl']){
						//用户有头像，查询用户头像
						$.post(webRoot+"/system/100101103100X",{imgId:data['imgUrl']},function(reslt){
			    			if(reslt&&reslt.success){
			    				$('#txt_imgRealUrl').attr('src',reslt.data);
			    			}
			    		})
					}else{
						//用户没有头像，设置默认头像
						if(data['sex']==2){
							$('#txt_imgRealUrl').attr('src',webRoot+'/_sys/images/wan.png');
						}else{
							$('#txt_imgRealUrl').attr('src',webRoot+'/_sys/images/man.png');
						}
					}
					
					$("#addOrModify_modal_title").text("新增员工");
					var disUpId = ["realName","sex","birthDate","idCard","education","specilRole"];
					for (var i in disUpId){
						var _object = $("#txt_"+disUpId[i]+",#sel_"+disUpId[i]);
						if(_object.size()>0){
							_object.removeAttr("disabled title");
						}
					}
					for(var _key in data){
						var _object = $("#txt_"+_key+",#sel_"+_key);
						if(_object.size()>0){
							if(data[_key]){
								if (_key == "birthDate"){
									_object.val(data[_key].substring(0,10));
								}else{
									_object.val(data[_key]);
								}
								_object.attr("disabled","disabled");
								_object.attr("title","此信息不能修改");
							}else{
								_object.removeAttr("disabled","disabled");
								_object.removeAttr("title","此信息不能修改");
							}
						}
					}
					if (data.selectKey==4&&data.selectValue){
						$("#txt_idCard").val(data.selectValue);
					}
					$("#btn_100101103101_save").hide();
					$("#btn_100101103100_save").show();
					
					setTimeout(function(){
						$("#bs-addOrModify-modal-lg").modal("show");
					},500)
				}
			});
		})
		
		/*****************************   提交添加员工   ******************************/
		$("#btn_100101103100_save").on("click",function(){
			var isBlank = null;
			
			var tempJSon = {};
			$("#frm_addOrModify , input[id^='txt_'],select[id^='sel_']").each(function(){
				if ($(this).attr("name")!=undefined){
					if($(this).attr("name")=='imgUrl'||$(this).val()){
						if($(this).attr("name")=='orgEmail'){
							var pattern = /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/;
							if(!pattern.test($(this).val())){
								isBlank = "邮箱格式不正确";
								return false;
							}
						}
						tempJSon[$(this).attr("name")]=$(this).val();
					}else{
						isBlank = "请完善信息后再提交";
						return false;
					}
				}
			})
			if (isBlank) {
				return _common.alert(true,isBlank);
			}else{
				$("#bs-addOrModify-modal-lg").modal("hide");
				_common.loading(true,"正在保存中...");
				$.post(webRoot+"/system/100101103100",tempJSon,function(reslt){
	    			setTimeout(function(){
	    				_common.loading(false);
	    				if(reslt){
	    					if(reslt.success){
	    						_targeTable.refresh();
	    					}else{
	    						setTimeout(function(){_common.alert(true,reslt.subMsg);},300)
	    					}
		    			}
	    			},1000)
	    		})
			}
		})
		
		/*****************************   修改员工按钮    ***************************/
		$("#btn_100101103101").on("click",function(){
			var _selectOtpns = _targeTable.getSelections();
			if(_selectOtpns&&_selectOtpns.length==1){
				_common.loading(true,"正在加载中...");
				setTimeout(function(){
					$('#frm_addOrModify').get(0).reset();
					$("#addOrModify_modal_title").text("修改员工");
					var temp = {
						userId:userInfo.userId//员工id
					};
					submitData("100101103104", temp, {
						success:function(res){
							for(var _key in res.data){
								var _object = $("#txt_"+_key+",#sel_"+_key);
								if(_object.size()>0){
									if (_key == "birthDate"){
										if(res.data[_key]){_object.val(res.data[_key].substring(0,10));}
									}else if(_key == "imgRealUrl"){
										if(res.data[_key]){
											var d = res.data[_key].replace(/\\/g,"/");
											_object.attr("src",d);
										}else{
											if(res.data["sex"]==2){
												$('#txt_imgRealUrl').attr('src',webRoot+'/_sys/images/wan.png');
											}else{
												$('#txt_imgRealUrl').attr('src',webRoot+'/_sys/images/man.png');
											}
										}
									}else {
										if(res.data[_key]!=null){
											_object.val(res.data[_key]);
										}
									}
								}
							}
							//禁掉不可修改框
							var disUpId = ["sex","birthDate","idCard","education","specilRole"];
							for (var i in disUpId){
								var _object = $("#txt_"+disUpId[i]+",#sel_"+disUpId[i]);
								if(_object.size()>0){
									if(i==0&&!_object.val()){
										_object.val(0);
										continue;
									}
									if(i==1&&!_object.val()){
										continue;
									}
									if(i==3&&!_object.val()){
										_object.val(5);
										continue;
									}
									if(i==4&&(_object.val()<=2)){
										continue;
									}
									
									_object.attr("disabled","disabled");
									_object.attr("title","此信息不能修改");
								}
							}
							$("#btn_100101103100_save").hide();
							$("#btn_100101103101_save").show();
							_common.loading(false);
							$("#bs-addOrModify-modal-lg").modal("show");//打开弹出层修改
						}
					});
				},1000)
			}else{
				_common.alert(true,"请选择一项进行操作.");
			}
		})
		
		/*****************************   提交修改员工   ******************************/
		$("#btn_100101103101_save").on("click",function(){
			var isBlank = null;
			
			var tempJSon = {userId:userInfo.userId};
			$("#frm_addOrModify , input[id^='txt_'],select[id^='sel_']").each(function(){
				if ($(this).attr("name")!=undefined&&$(this).attr("disabled")!="disabled"){
					if($(this).attr("name")=='imgUrl'||$(this).val()){
						if($(this).attr("name")=='orgEmail'){
							var pattern = /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/;
							if(!pattern.test($(this).val())){
								isBlank = "邮箱格式不正确";
								return false;
							}
						}
						if($(this).attr("name")=='mobile'){
							var pattern = /^1[3|4|5|7|8][0-9]{9}$/;
							if(!pattern.test($(this).val())){
								isBlank = "手机格式不正确";
								return false;
							}
						}
						tempJSon[$(this).attr("name")]=$(this).val();
					}else{
						isBlank = "请完善信息后再提交";
						return false;
					}
				}
			})
			if (isBlank) {
				return _common.alert(true,isBlank);
			}else{
				$("#bs-addOrModify-modal-lg").modal("hide");
				_common.loading(true,"正在保存中...");
				$.post(webRoot+"/system/100101103101",tempJSon,function(reslt){
	    			setTimeout(function(){
	    				_common.loading(false);
	    				if(reslt){
	    					if(reslt.success){
	    						_targeTable.refresh();
	    					}else{
	    						setTimeout(function(){_common.alert(true,reslt.subMsg);},300)
	    					}
		    			}
	    			},1000)
	    		})
			}
		})
		
		/*****************************   删除员工按钮    ***************************/
		$("#btn_100101103102").on("click",function(){
			var _selectOtpns = _targeTable.getSelections();
			if(_selectOtpns&&_selectOtpns.length==1){
				_common.alert(true,"你确定要删除"+userInfo.realName+"吗?",function(val){if (val == 1) {
					var temp = {
						userId:userInfo.userId	//员工id
					};
					submitData("100101103102", temp, {complete:function(){_targeTable.refresh()}});
				}},2);
			} else {
				_common.alert(true,"请选择要删除的员工.");
			}
		})
		
		/*****************************   检索    ***************************/
		$("#btn_100101103103").on("click",function(){
			$('#frm_100101103103').get(0).reset();
			$("#bs-100101103103-modal-lg").modal("show");
		})
		/*****************************   提交检索    ***************************/
		$("#btn_100101103103_save").on("click",function(){
			isSearch=true;
			
			if($("#sel_searchKey").val()==0&&$("#sel_searchValue").val()){
				return _common.alert(true,"关键字查询,请选择关键字类型");
			}
			$("#bs-100101103103-modal-lg").modal("hide");
			_targeTable.refresh()})
		
		/*****************************   查询员工详情    ***************************/
		$("#btn_100101103104").on("click",function(){
			var _selectOtpns = _targeTable.getSelections();
			if(_selectOtpns&&_selectOtpns.length==1){
				_common.loading(true,"正在加载中...");
				setTimeout(function(){
					var temp = {
							userId:userInfo.userId//员工id
						};
						submitData("100101103104", temp, {success:function(data){
							var info = data.data;
							for (var _key in info){
								var _object = $("#info_"+_key);
								if(_key == "birthDate"){
									_object.text(function(){if(info.birthDate){return info.birthDate.substring(0,10);}})
								}else if(_key == "state"){
									_object.text(function(){if(info.state){switch(info.state||0){case 1:return "生效";case 2:return "未生效"}}})
								}else if(_key == "sex"){
									_object.text(function(){if(info.sex){switch(info.sex||0){case 1:return "男";case 2:return "女";default:return "默认"}}})
								}else if(_key == "education"){
									_object.text(function(){if(info.education){switch(info.education||0){case 1:return "博士";case 2:return "研究生";case 3:return "本科";case 4:return "专科";case 5:return "其他"}}})
								}else if(_key == "inauType"){
									_object.text(function(){if(info.inauType){switch(info.inauType||0){case 1:return "正式";case 2:return "临时";case 3:return "实习";case 4:return "其他"}}})
								}else if(_key == "enabled"){
									_object.text(function(){if(info.enabled){switch(info.enabled||0){case 1:return "启用";case 2:return "未启用";}}})
								}else if(_key == "invitType"){
									_object.text(function(){if(info.invitType){switch(info.invitType||0){case 1:return "不邀请";case 2:return "短信邀请";case 3:return "邮件邀请";}}})
								}else if(_key == "imgRealUrl"){
									if(info[_key]){
										_object.attr("src", info[_key]);
									}else{
										if(info.sex==2){
											$('#txt_imgRealUrl').attr('src',webRoot+'/_sys/images/wan.png');
										}else{
											$('#txt_imgRealUrl').attr('src',webRoot+'/_sys/images/man.png');
										}
									}
								}else{
									_object.text(function(){if(info[_key]){return info[_key]}else{return "未设置"}});
								}
							}
							_common.loading(false);
							$("#bs-100101103104-modal-lg").modal("show");
						}})
				},1000)
			} else {
				_common.alert(true,"请选择要查看的员工.");
			}
		})
		
		/*****************************   是否生效    ***************************/
		$("#btn_100101103108").on("click",function(){
			var _selectOtpns = _targeTable.getSelections();
			if(_selectOtpns&&_selectOtpns.length==1){
				_common.alert(true,"你确定要将"+userInfo.realName+"设为"+(userInfo.state==1?"未生效":"生效")+"吗?",function(val){if (val == 1) {
					var temp ={
						userId:userInfo.userId,	//员工id
						state:userInfo.state==1?2:1,//是否生效
						enabled:userInfo.state==1?2:0//是否启用,如果设为未生效,则设为未启用
					}
					submitData("100101103101", temp, {success:function(){_targeTable.refresh();}});// 提交数据
				}},2);
			} else {
				_common.alert(true,"请选择要修改的员工.");
			}
			
		})
		
		/*****************************   是否启用    ***************************/
		$("#btn_100101103109").on("click",function(){
			var _selectOtpns = _targeTable.getSelections();
			if(_selectOtpns&&_selectOtpns.length==1){
				if(userInfo.state == 1){
					_common.alert(true,"你确定要"+(userInfo.enabled==1?"停用":"启用")+userInfo.realName+"吗?",function(val){if (val == 1) {
						var temp = {
								userId:userInfo.userId,	//员工id
								enabled:userInfo.enabled==1?2:1
						};
						submitData("100101103101", temp, {complete:function(){_targeTable.refresh()}});
					}},2);
				}else{
					_common.alert(true,"请将该员工生效后再进行设置.");
				}
			} else {
				_common.alert(true,"请选择要修改的员工.");
			}
		})
		
		/*****************************   设置部门和角色权限按钮    ***************************/
		$("#btn_100101103105").on("click",function(){
			var _selectOtpns = _targeTable.getSelections();
			if(_selectOtpns&&_selectOtpns.length==1){
				_common.loading(true,"正在加载中,请稍后...");
				if (_roleTargeTable != null) {
					_roleTargeTable.destroy();
				}
				loadingTree({open:true,treeName:"departTree",url:"100101102106",onClick:onClickDepart});
				setTimeout(function(){
					_common.loading(false);
					if ($.fn.zTree.getZTreeObj("departTree") != null) {// 部门下有数据
						$("#bs-100101103105-modal-lg").modal("show");//打开弹出层设置权限
					} else {
						_common.alert(true,"未查询到任何数据!");
					}
				},500);
			}else{
				_common.alert(true,"请选择一项进行操作.");
			}
		})
		/*****************************   保存设置部门和角色权限   ***************************/
		$("#btn_100101103105_save").on("click",function(){
			var _selectOtpns = _roleTargeTable.getSelections();//获取所有勾选的行
			var addRdpIds= [];
			var delRdpIds= [];
			$.each(userDepRole,function(j,m){//所有数据
				var bl = false; //勾选状态(true:勾选,false:未勾选)
				if(_selectOtpns) {
					$.each(_selectOtpns, function(i,n){
						if(n.id==m.id){bl = true;}
					})
				}
				if(m.blUserRole == 1 && bl) {//未拥有当前部门下该角色并且勾选上
					addRdpIds.push(m.id);
				}
				if(m.blUserRole == 0 && !bl){//已拥有当前部门下该角色并且未勾选上
					delRdpIds.push(m.id);
				}
			});
			var temp={
				userId:userInfo.userId,//用户编号
				departCode:code,//新增的时候部门编号,当设置部门角色权限的时候必须传入部门编号
				addRdpIdsStr:addRdpIds.join(","),//新增部门角色权限ID;
				delRdpIdsStr:delRdpIds.join(",")//删除部门角色权限ID;
			}
			submitData("100101103105", temp, {complete:function(){$("#bs-100101103105-modal-lg").modal("hide");}});// 提交数据
		})
		
		/*****************************   设置特殊权限按钮    ***************************/
		$("#btn_100101103106").on("click",function(){
			var _selectOtpns = _targeTable.getSelections();
			if(_selectOtpns&&_selectOtpns.length==1){
				_common.loading(true,"正在加载中,请稍后...");
				$("#x_content_02").css("height",$('#ifrmContent', parent.document).height()-230);
				var treeObj = $.fn.zTree.getZTreeObj("spacilMenuTree");
				var nodes = null;
				
				if (treeObj == null){
					loadingTree({treeName:"spacilMenuTree",url:"100101102104",checkEnable:true});//加载当前机构所有的菜单树默认所有勾选
					treeObj = $.fn.zTree.getZTreeObj("spacilMenuTree");
					if(treeObj != null){
						nodes = treeObj.getNodes();
					}else{
						return _common.alert(true,"系统繁忙,加载失败!");
					}
				} else {
					nodes = treeObj.getNodes();
					for (var i=0, l=nodes.length; i < l; i++) {
						treeObj.setChkDisabled(nodes[i], false,true,true);
					}
					treeObj.checkAllNodes(false);
				}
				
				if (nodes.length > 0) {
					$("#myModalLabel-100101103106").text("特殊权限");
					checkedSpacilTreeNode();//将当前员工已有的权限勾选上
					$("#modal-footer-100101103106").show();
				} else {
					_common.loading(false);
					_common.alert(true,"未查询到任何数据,请刷新再试!");
				}
			}else{
				_common.alert(true,"请选择一项进行操作.");
			}
		})
		/*****************************   保存设置特殊权限   ***************************/
		$("#btn_100101103106_save").on("click",function(){
			var treeObj = $.fn.zTree.getZTreeObj("spacilMenuTree");
			var checkedNodes = treeObj.getCheckedNodes(true);
			
			var addPowers = getAddPowers(checkedNodes,userAllPower);
			var delPowers = getDelPowers(checkedNodes,userAllPower);
			
			var temp ={
				userId:userInfo.userId,//用户编号
				addPowersStr:addPowers.join(","),//新增特殊权限
				delPowersStr:delPowers.join(",") //删除特殊权限
			}
			if (temp.addPowersStr != "" || temp.delPowersStr != "") {
				submitData("100101103106", temp, {complete:function(){$("#bs-100101103106-modal-lg").modal("hide");}})
			} else {
				_common.alert(true,"未进行任何修改!");
			}
		})
		
		/*****************************   查询用户权限   ***************************/
		$("#btn_100101103107").on("click",function(){
			var _selectOtpns = _targeTable.getSelections();
			if(_selectOtpns&&_selectOtpns.length==1){
				_common.loading(true,"正在加载中...");
				$("#x_content_02").css("height",$('#ifrmContent', parent.document).height()-180);
				
				var treeObj = $.fn.zTree.getZTreeObj("spacilMenuTree");
				var nodes = null;
				
				if(treeObj == null){
					loadingTree({treeName:"spacilMenuTree",url:"100101102104",checkEnable:true});//加载当前机构所有的菜单树默认所有勾选
					treeObj = $.fn.zTree.getZTreeObj("spacilMenuTree");
					nodes = treeObj.getNodes();
				}else{
					nodes = treeObj.getNodes();
					for (var i=0, l=nodes.length; i < l; i++) {
						treeObj.setChkDisabled(nodes[i], false,true,true);
					}
					treeObj.checkAllNodes(false);
				}
				
				if (nodes.length > 0) {
					$("#myModalLabel-100101103106").text("所有权限");
					$("#modal-footer-100101103106").hide();
					checkedSpacilTreeNode();//将当前员工已有的权限勾选上
					setTimeout(function(){
						for (var i=0, l=nodes.length; i < l; i++) {
							treeObj.setChkDisabled(nodes[i], true,true,true);
						}
					},1000);
				}else{
					_common.loading(false);
					_common.alert(true,"未查询到任何数据,请刷新再试!");
				}
			}else{
				_common.alert(true,"请选择一项进行操作.");
			}
		})
	});
	
	/***********************************************************
	 * 员工基本信息表
	 */
	var TableInit = function(targeTbArg) {
		var oTableInit = new Object();
		// 得到查询的参数
		oTableInit.queryParams = function(params) {
			var temp = {
				pageSize: params.pageSize, 				//页面大小
				pageIndex : isSearch?1:params.pageIndex, //页码
				selectKey:$("#sel_searchKey").val(),	//查询键
				selectVal:$("#sel_searchValue").val(),	//查询值
				departCode:$("#sel_departCode").val(),	//部门
				inauType:$("#sel_search_inauType").val(),//用户公司状态
				state:$("#sel_state").val(),			//状态
				startTime:$("#txt_startDate").val(),	//开始时间
				endTime:$("#txt_endDate").val()			//结束时间
			}
			return temp;
		};
		// 初始化Table
		oTableInit.Init = function() {
			return targeTbArg.bootstrapTable("destroy").bootstrapTable({
				url : webRoot+'/system/100101103103', // 请求后台的URL（*）
				queryParams : oTableInit.queryParams,// 传递参数（*）
				uniqueId : "userId", // 每一行的唯一标识，一般为主键列
				onCheck:onCheckUser,	//勾选事件
				onLoadSuccess:function(d){
					if(d.success){
						if (d.data.data.length) {
							return _targeTable.resetView({height:($('#ifrmContent', parent.document).height()-140)})
						}
					}
					_targeTable.resetView({height:($('#ifrmContent', parent.document).height()-90)})
				},
				height:($('#ifrmContent', parent.document).height()-90),
				columns : [{
					field : 'checked',
		            checkbox : true,
				}, {
					field:'realName',
					title:'姓名',
					align:'center'
				}, {
					field:"orgEmail",
					title:"邮箱",
					align:'center'
				},{
					field:"mobile",
					title:"手机",
					align:'center'
				},{
					field:"jonNum",
					title:"工号",
					align:'center'
				},{
					field:"inauType",
					title:"类型",
					align:'center',
					formatter: function(v){
						 switch(v||0){
						 	case 1:return "<font color='green'>正式</font>";
						 	case 2:return "<font color='green'>临时</font>";
						 	case 3:return "<font color='green'>实习</font>";
						 	case 4:return "<font color='green'>其他</font>";
						 }
					}
				},{
					field:"state",
					title:"状态",
					align:'center',
					formatter: function(v){
						 switch(v||0){
						 	case 1:return "<font color='green'>已生效</font>";
						 	case 2:return "<font color='red'>未生效</font>";
						 }
					}
				},{
					field:"enabled",
					title:"启用",
					align:'center',
					formatter: function(v){
						 switch(v||0){
						 	case 1:return "<font color='green'>启用</font>";
						 	case 2:return "<font color='red'>停用</font>";
						 }
					}
				},{
					field:"invitType",
					title:"邀请",
					align:'center',
					formatter: function(v,row,index){
						if(row.enabled==1&&row.state==1){
							var userId = row.userId;
							var realName = row.realName;
							var orgEmail = row.orgEmail;
							switch(v||0){
							case 1:return "<div class='btn-group'><button data-toggle='dropdown' class='btn btn-default dropdown-toggle btn-xs' type='button' aria-expanded='false'><font color='green'>不邀请   </font><span class='caret'></span></button><ul role='menu' class='dropdown-menu'><li><a href='javascript:void(0)'>不邀请</a></li><li><a href='javascript:void(0)' onClick='invite(2,\""+userId+"\",\""+realName+"\",\""+orgEmail+"\","+index+")'>短信邀请</a></li><li><a href='javascript:void(0)' onClick='invite(3,\""+userId+"\",\""+realName+"\",\""+orgEmail+"\","+index+")'>邮件邀请</a></li></ul></div>";
							case 2:return "<div class='btn-group' title='短信邀请'><button data-toggle='dropdown' class='btn btn-default dropdown-toggle btn-xs' type='button' aria-expanded='false'><font color='green'>已邀请   </font><span class='caret'></span></button><ul role='menu' class='dropdown-menu'><li><a href='javascript:void(0)' onClick='invite(1,\""+userId+"\",\""+realName+"\",\""+orgEmail+"\","+index+")'>不邀请</a></li><li><a href='javascript:void(0)'>短信邀请</a></li><li><a href='javascript:void(0)' onClick='invite(3,\""+userId+"\",\""+realName+"\",\""+orgEmail+"\","+index+")'>邮件邀请</a></li></ul></div>";
							case 3:return "<div class='btn-group' title='邮件邀请'><button data-toggle='dropdown' class='btn btn-default dropdown-toggle btn-xs' type='button' aria-expanded='false'><font color='green'>已邀请   </font><span class='caret'></span></button><ul role='menu' class='dropdown-menu'><li><a href='javascript:void(0)' onClick='invite(1,\""+userId+"\",\""+realName+"\",\""+orgEmail+"\","+index+")'>不邀请</a></li><li><a href='javascript:void(0)' onClick='invite(2,\""+userId+"\",\""+realName+"\",\""+orgEmail+"\","+index+")'>短信邀请</a></li><li><a href='javascript:void(0)'>邮件邀请</a></li></ul></div>";
							}
						}else{
							switch(v||0){
							case 1:return "<font title='请启用后再设置'>不邀请</font>";
							case 2:return "<font title='请启用后再设置'>短信邀请</font>";
							case 3:return "<font title='请启用后再设置'>邮件邀请</font>";
							}
						}
					}
				},{
					field:"createTime",
					title:"创建时间",
					align:'center',
					formatter:function(v){
						 if(v){return v.substring(0,10);}
					}
				}
				]
			});
		};
		//设置获取选择行
		oTableInit.getSelections = function(){return targeTbArg.bootstrapTable('getSelections');}
		//设置获取所有数据
		oTableInit.getData = function(){return targeTbArg.bootstrapTable('getData');}
		//重新设置视图
		oTableInit.resetView = function(height){return targeTbArg.bootstrapTable('resetView',height);}
		//更新单元格
		oTableInit.updateCell = function(param){return targeTbArg.bootstrapTable('updateCell',param);}
		//刷新列表
		oTableInit.refresh = function(){
			//内容刷新
			targeTbArg.bootstrapTable('refresh',{refCallBack:function(){
				isSearch = false;
				xbdunRequire("common").loading(false);	//关闭加载
			}})
		}
		//初始化加载数据
		oTableInit.Init();
		return oTableInit;
	};
	/*************
	 * 	加载树
	 * 
	 * @param params {loading 是否显示加载框,open 是否全部展开,treeName 树形结构ID,url 查询地址}
	 * @param setting
	 * @returns
	 */
	function loadingTree(params){
		var setting = {
			data:{
				key:{title:"title"},
				simpleData:{enable:true,pIdKey:"pid"}
			},
			view:{
				fontCss:{'font-weight':'bold'},showIcon:false
			},
			check: {
				enable:params.checkEnable==undefined?false:params.checkEnable,
			},
			callback: {
				onAsyncSuccess: params.onAsyncSuccess,
				beforeClick:params.beforeClick,
				onClick:params.onClick,
				onCheck:params.onCheck
			}
		};
		
		if (params.loading==undefined?false:params.loading) {
			_common.loading(true, "正在加载中,请稍后...");
		}
		$.ajax({
			type : "post",
			url : webRoot+ "/system/"+params.url,
			data:params.temp,
			async:false,
			success : function(data) {
				if (data.success) {
					if (data.data) {
						$.fn.zTree.init($("#"+params.treeName), setting, data.data);
						$.fn.zTree.getZTreeObj(params.treeName).expandAll(params.open==undefined?false:params.open);// 将加载的树全部展开
					}
				}else {
					_common.loading(false);
					_common.alert(true, data.msg);
				}
			},
			complete:function (){
				if (params.loading==undefined?false:params.loading) {
					_common.loading(false);
				}
			}
		})
	}
	
	/*********************
	 * 	调用ajax
	 * 
	 * @param url		地址
	 * @param temp		上传参数
	 * @param fnSubmit	回调函数 {success:fn,fail:fn,init:,complete}
	 * @returns
	 */
	function submitData(url, temp, fnSubmit){
		if (fnSubmit.init != null) {
			fnSubmit.init();
		}
		$.ajax({
			type:"post",
			url:webRoot+"/system/"+url,
			data:temp,
			async:false,
			success : function(data) {
				if (data) {
					if (data.success) {
						setTimeout(function(){if(fnSubmit.success){fnSubmit.success(data)}},500);
					} else {
						_common.loading(false);
						setTimeout(function(){_common.alert(true,data.subMsg);},500);
					}
				}
			},
			complete:function (){
				_common.loading(false);
				if (fnSubmit.complete){
					fnSubmit.complete();
				}
			}
		})
	}
	/*************************************
	 * 点击部门--加载该部门下的角色
	 * @param event
	 * @param treeId
	 * @param treeNode
	 * @returns
	 */
	function onClickDepart(event, treeId, treeNode, clickFlag) {
		code = treeNode.id;
		_roleTargeTable = new RoleTableInit($('#tb_depart_role_list'));
	};
	
	/****************
	 * 勾选员工--为全局员工变量赋值
	 * @param row
	 * @returns
	 */
	function onCheckUser(row) {
		userInfo = row;
	}
	
	/*****************************   
	 * 工号随机生成按钮   
	 * 
	 * 随机生成6位员工工号 两位字母加四位数字
	 *******************************/
	function createJonNum(){
		var code = "QWERTYUIOPASDFGHJKLZXCVBNM";
		var str = code.charAt(Math.random()*code.length)+code.charAt(Math.random()*code.length);
		for (var i = 0; i < 4 ; i++) {
			str+=Math.floor(Math.random()*10);
		}
		$("#txt_jonNum").val(str);
	}
	
	/*****************************   
	 * 勾选当前员工已有的权限
	 * 
	 *******************************/
	function checkedSpacilTreeNode(){
		submitData("100101103106X", {userId:userInfo.userId,type:0}, {success:function(data){
			userAllPower = data.data;
			var treeObj = $.fn.zTree.getZTreeObj("spacilMenuTree");
			var nodes = treeObj.transformToArray(treeObj.getNodes());
			$.each(nodes,function(i, n){
				$.each(data.data,function(i, id){
					if (n.id == id) {
						treeObj.checkNode(n, true, false);
					}
				})
			})
			_common.loading(false);
			$("#bs-100101103106-modal-lg").modal("show");
		}});
	}
	
	/*****************************   
	 * 获取增加的特殊权限
	 * 
	 * @description 选中中有但是在员工已有的权限中没有的
	 * @param checkedNodes 选中的节点
	 * @param userAllPower 员工已有的所有权限
	 *******************************/
	function getAddPowers(checkedNodes,userAllPower){
		var result = [];
		$.each(checkedNodes,function(i,check){
			var bl = true;
			$.each(userAllPower,function(j,id){
				if (check.id == id) {
					bl = false;
				}
			})
			if (bl) {
				 result.push (check.id);
			}
		})
		return result;
	}
	
	/*****************************   
	 * 获取删除的特殊权限
	 * 
	 * @description 员工已有的所有权限中有但是选中里没有
	 * @param checkedNodes 选中的节点
	 * @param userAllPower 员工已有的所有权限
	 *******************************/
	function getDelPowers(checkedNodes,userAllPower){
		var result = [];
		$.each(userAllPower,function(i,id){
			var bl = true;
			$.each(checkedNodes,function(j,check){
				if (id == check.id) {
					bl = false;
				}
			})
			if (bl) {
				result.push (id);
			}
		})
		return result;
	}
	
	/********* 修改邀请方式  **********/
	function invite(num,userId,realName,orgEmail,index){
		var alertInfo = "";
		switch(num){
		case 1:	alertInfo = "您确定要取消邀请吗?";break;
		case 2:	alertInfo = "您确定要使用短信邀请吗?";break;
		case 3:	alertInfo = "您确定要使用邮件邀请吗?";break;
		}
		_common.alert(true,alertInfo,function(v){
				if(v==1){//修改邀请
					setTimeout(function(){
						_common.loading(true,"正在保存中...");
					$.post(webRoot+"/system/100101103101X",{userId:userId,inviteType:num,realName:realName,orgEmail:orgEmail},function(reslt){
						if(reslt){
							setTimeout(function(){
								_common.loading(false);
								if(reslt.success){
									if(num ==1){
										_common.alert(true,"已成功取消邀请!");
									}else{
										_common.alert(true,"已成功发送邀请!");
									}
									_targeTable.updateCell({index:index,field:"invitType",value:num});
								}else{
									_common.alert(true,"修改邀请方式失败!原因是:"+reslt.subMsg);
								}
							},1000)
						}
					})
				},300)
			}
		},2)
		
	}
